package net.sky.oa.dao.docs.impl;


import java.util.ArrayList;
import java.util.List;

import net.sky.oa.dao.SkyBaseDaoImpl;
import net.sky.oa.dao.docs.DocFolderDao;
import net.sky.oa.model.DocFolder;

import org.springframework.stereotype.Repository;

@SuppressWarnings("unchecked")
@Repository
public class DocFolderDaoImpl extends SkyBaseDaoImpl<DocFolder> implements DocFolderDao {

	public DocFolderDaoImpl() {
		super(DocFolder.class);
	}

	public List<DocFolder> findByParentId(int type,Long deptId,Long userId, Long parentId){
//		StringBuilder hql=new StringBuilder("from DocFolder df where df.type=? and df.parentId=? ");
		StringBuilder hql=new StringBuilder("select new DocFolder(df.id,df.folderName,df.parentId,df.type)from DocFolder df where df.type=? ");
		List list=new ArrayList();
		list.add(type);
//		list.add(parentId);
		try{
			if(deptId!=-1){
				hql.append(" and df.dept.id=? ");
				list.add(deptId);
			}
			if(userId!=-1){
				hql.append(" and df.user.id=? ");
				list.add(userId);
			}
			hql.append(" order by  df.id");
			return findByHql(hql.toString(),list.toArray());
		}catch(Exception e)
		{
			e.printStackTrace();
			return null;
		}
	}
	

}
